<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>mustache</title>
</head>
<body>
  <p>mustache部分原理-正则匹配</p>
  <div id="dom"></div>
  <script>
    var template = `<h1>我买了一个{{thing}},好{{mod}}</h1>`
    var data = {
      thing:'手机',
      mod:'开心'
    }
    // 正则中()可以捕获，例如下面$1为捕获的结果
    console.log(template.replace(/\{\{(\w+)\}\}/g,function(str,$1){
      console.log(str,$1)
      return data[$1]
    }))
  </script>
</body>
</html>